package com.industry.framework.common.utils;

import cn.dev33.satoken.secure.SaSecureUtil;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
@NoArgsConstructor(access = AccessLevel.PUBLIC)
public class RSAUtils {
    private static String publicKey;
    private static String privateKey;

    @Value("${key.public}")
    private void setPublicKey(String param) {
        publicKey = param;
    }

    @Value("${key.private}")
    private void setPrivateKey(String param) {
        privateKey = param;
    }

    // 使用公钥加密数据
    public static String encrypt(String data) {
        // 使用公钥加密
        return SaSecureUtil.rsaEncryptByPublic(publicKey, data);
    }

    // 使用私钥解密数据
    public static String decrypt(String encryptedData) {
        // 使用私钥解密
        return SaSecureUtil.rsaDecryptByPrivate(privateKey, encryptedData);
    }
}
